#pragma once
#include <map>
using namespace std;

#include "../../../../../work_project/Code/include/isystemfile.h"
#include "../../../../../work_project/Code/include/iglobalfunc.h"
#include "../../../../../work_project/Code/include/kl/kllib.h"

struct CGridPos
{
	struct Pos
	{
		short x;
		short y;
	};
	typedef int ID;
	CGridPos()
	{
		id = 0;
	}
	CGridPos(short xValue, short yValue)
	{
		pos.x = xValue;
		pos.y = yValue;
	}
	union
	{
		ID id;
		Pos pos;
	};
	void operator = (CGridPos& pos)
	{
		id = pos.id;
	}
};;

class CGameMap;
class CMapBuilderView;
class CMapGrid
{
	friend CGameMap;
	friend CMapBuilderView;
public:
	enum DefaultValue
	{
		MIX_GRID_SIZE			= 32,
		DEFAULT_GRID_SIZE		= 48,
	};
private:
	enum LinkPath
	{
		LINKPATH_LEFT,
		LINKPATH_LEFT_TOP,
		LINKPATH_TOP,
		LINKPATH_RIGHT_TOP,
		LINKPATH_RIGHT,
		LINKPATH_RIGHT_BOTTOM,
		LINKPATH_BOTTOM,
		LINKPATH_LEFT_BOTTOM,
		LINKPATH_COUNT
	};
public:
	CMapGrid();
	CMapGrid(int nGridType);
	virtual ~CMapGrid();
	void DrawBlock(CDC* pDrawDC, CRect rcBlock, BOOL bSelected);
	void DrawLinkLineNext(CDC* pDrawDC, CRect rcSelf, CRect rcDst);
	void DrawLinkLineNextBegin(CDC* pDrawDC, CRect rcSelf, CRect rcDst);
	void DrawLinkLinePrev(CDC* pDrawDC, CRect rcSelf, CRect rcDst);
	void DrawLinkLinePrevBegin(CDC* pDrawDC, CRect rcSelf, CRect rcDst);
protected:
	void SaveData(CArchive& ar);
	void LoadData(CArchive& ar);
private:
	float get_pen_pixel(CRect rcBlock) { return 2.0f + (rcBlock.Width() - CMapGrid::DEFAULT_GRID_SIZE) / 16; }
private:
//	COLORREF m_clrBlock;
	CDataGridInfo::_DATA m_GridData;
};
